clear
clc
close all

% Set directory


addpath(genpath('Fig_X'))


% Output folder for figures
Figures_path=strcat('.\Figures');

% Graphic settings
defpos = [100         100        1500         700];
set(0,'defaultfigurepos',defpos);


set(0,'defaultlinelinewidth',2.5);
set(0,'defaultaxesfontsize',14);  %12
set(0,'defaulttextfontsize',12);  %12
set(0,'defaultlinelinewidth',2.5);

CalibratedValuesFileName='params\CalibratedParameters'; %parameters of the stylized NK model
[param,paranames]=xlsread(CalibratedValuesFileName,'param');

%% Solve the Stylized Model

[GG,RR,eu,SDX,flag,ACont,ALag,ALead,PSI] =  mod_flexprice_SSrules(param,2);

%% Upload the estimated shocks for simulations
[EstimatedShocks]=csvread('.\Fig_X\EstimatedUnfundedTransferShocks.csv');
TT=EstimatedShocks(:,1);
ss= -EstimatedShocks(:,2);  %invert the sign cause in the stylized model we have unfunded shocks to the primary surplus
[otpt2]=csvread('.\Fig_X\RoleUnfunded.csv');
infl_ss=otpt2(:,2); %Retrieving the series of the fiscal inflation in the Quantitative Model

%% Simulating the Stylized Model with Estimated Unfunded Fiscal Shocks
ss_mod=zeros(length(GG),length(TT));
ss_mod(:,1)=RR(:,3)*ss(1);
for t=2:length(TT)
    ss_mod(:,t)=GG*ss_mod(:,t-1)+RR(:,3)*ss(t);
end

%% Do the figure

%Upload the estimation output of the Quantitative Model
load ('.\Estimation\BFM_mod\ver01\FirstSampleOutput\end 2007.75 csminwel BFMPrior 02 03 23\workspace');
pistar400=model.param(13)*4; % steady state inflation in the Quantitative Model
YY=xlsread('.\Fig_X\Data\GPDdeflator.xlsx','F2:F252');

figure
plot(TT,YY*4,':r') %Data
hold on
plot(TT,infl_ss+pistar400,'b'); % Quantitative model
hold on
plot(TT,400*ss_mod(6,:)'+pistar400,'--k'); %Stylized model
hold on
plot(TT,TT*0,'--r','LineWidth',1.2);
hold off
axis tight
legend('Actual inflation','Quantitative model','Stylized model','Location','Best')

savefigure_pdf(strcat(Figures_path,'\Figure_X'));
